package com.matriq.cloudmanager.fragment;
import com.matriq.cloudmanager.R;
import com.matriq.cloudmanager.AttendanceActivity;
import com.matriq.cloudmanager.ClassScheduleActivity;
import com.matriq.cloudmanager.ClassWorkActivity;
import com.matriq.cloudmanager.CourseEvalListActivity;
import com.matriq.cloudmanager.DiscussActivity;
import com.matriq.cloudmanager.MyApp;
import com.matriq.cloudmanager.PersonInfoActivity;
import com.matriq.cloudmanager.TeachPlanActivity;
import com.matriq.cloudmanager.TeachResActivity;
import com.matriq.cloudmanager.TrainNoteActivity;
import com.matriq.cloudmanager.WeicourseActivity;
import com.matriq.cloudmanager.entity.User;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import net.lgpage.fragment.BaseFragment;

public class HomeFragment extends BaseFragment {
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		return inflater.inflate(R.layout.fm_home, container, false);
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		setViews();
		setEvents();
		loadData();
	}

	LinearLayout ll_ac[] = new LinearLayout[9];
	TextView tv_num;
	ImageButton ib;
	FrameLayout fm;
	ImageView imgAD;
	ScrollView sv;
	TextView tv_name;

	private void setViews() {
		ll_ac[0] = (LinearLayout) getView().findViewById(R.id.ll_ac0);
		ll_ac[1] = (LinearLayout) getView().findViewById(R.id.ll_ac1);
		ll_ac[2] = (LinearLayout) getView().findViewById(R.id.ll_ac2);
		ll_ac[3] = (LinearLayout) getView().findViewById(R.id.ll_ac3);
		ll_ac[4] = (LinearLayout) getView().findViewById(R.id.ll_ac4);
		ll_ac[5] = (LinearLayout) getView().findViewById(R.id.ll_ac5);
		ll_ac[6] = (LinearLayout) getView().findViewById(R.id.ll_ac6);
		ll_ac[7] = (LinearLayout) getView().findViewById(R.id.ll_ac7);
		ll_ac[8] = (LinearLayout) getView().findViewById(R.id.ll_ac8);
		tv_num = (TextView) getView().findViewById(R.id.tv_num);
		ib = (ImageButton) getView().findViewById(R.id.ib);
		fm = (FrameLayout) getView().findViewById(R.id.fm);
		imgAD = (ImageView) getView().findViewById(R.id.imgAD);
		sv = (ScrollView) getView().findViewById(R.id.sv);
		tv_name = (TextView) getView().findViewById(R.id.tv_name);
	}

	private void setEvents() {
		ib.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				toActivity(PersonInfoActivity.class);
			}
		});
		ll_ac[0].setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				toActivity(TeachPlanActivity.class);
			}
		});
		ll_ac[1].setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				toActivity(TeachResActivity.class);
			}
		});
		ll_ac[2].setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				toActivity(ClassScheduleActivity.class);
			}
		});
		ll_ac[3].setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				toActivity(AttendanceActivity.class);
			}
		});
		ll_ac[4].setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				toActivity(CourseEvalListActivity.class);
			}
		});
		ll_ac[5].setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				toActivity(DiscussActivity.class);
			}
		});
		ll_ac[6].setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				toActivity(ClassWorkActivity.class);
			}
		});
		ll_ac[7].setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				toActivity(TrainNoteActivity.class);
			}
		});
		ll_ac[8].setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				//toActivity(WeicourseActivity.class);
			}
		});
	}

	User obj;

	public void setData(User obj) {
		this.obj = obj;
		if(obj == null)return;
		tv_num.setText("学号:"+obj.getNO());
		tv_name.setText(""+obj.getName());
	}

	private void loadData() {
		setData(MyApp.getApp().getLoginObj());
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
	}

}